// JavaScript Document
/*
Caution:
If you want to call javascript function by anchor tab(<a></a>) 
you need place it at href
<a href="myFunction();" >click here </a>
*/
var otherTitleFirst ='other_title_textbox_';
var otherLinkFirst ='other_link_to_price_list_';
var otherUniformFirst = 'other_uniform_price_';
var slashChar = '| ';
var slash = addElementHTML('font','','','#333333',slashChar ) ;
var textPTPL ='Price Table Page Links';
var textS1 ='Link table configured rate';
var textS2_1 ='National uniform ';
var textS2_2 ='yen (including tax)';
function setInitializeAddNew(){
	var obj = document.getElementById("product_id");
	obj.setAttribute('readonly',false);
	}
function setInitializeEdit(){
	var obj= document.getElementById("product_id");
	obj.setAttribute('readonly',true);
	}
function save_edit_product(){
	// The first step - check empty text fill
	//if(!checkEmptyForm("frmNewProduct"))
	 //	return false;
	getAllValueOfRadioAndCheckboxArray("frmNewProduct");
	var frm =	document.getElementById("frmNewProduct");

	var text = tinyMCE.get('product_description').getContent();
		frm.product_description.value = text;	
/*	product_description_normal = document.getElementById("product_description_normal").value;
	if(parseInt(product_description_normal)==0)
		{
			frm.product_description. = frm.product_description_html_tag.value;
			var desc = tinyMCE.get('product_description').getContent();
			alert(frm.product_description_html_tag.value);
			alert(frm.product_description.value);
			frm.product_description.value = desc;	
			
		}*/
// get mobile description version
	 var val = getCheckedValue(frm.product_description_swich);
	if(val == 1){
		var text_2 = tinyMCE.get('product_description_on_mobile').getContent();
		frm.product_description_on_mobile.value = text_2;	
		frm.product_description_on_mobile.value = frm.product_description.value;
		}
	frm.submit();
	}
var preE5;	
function HighLightTR_Product_main(el,pid,pname,id_label){
		var backColor='#E7E7E7';
		var textColor='#00CC00';
		var selected=document.getElementById('id_first_line_product').value;
		var first_row=document.getElementById(selected);
		if(typeof(first_row)!='undefined'){
				first_row.style.color="#333333";
			}
		  if(typeof(preE5)!='undefined'){
				preE5.bgColor=orgBColor;
				preE5.style.color=orgTColor;
		 	 }
		document.getElementById(id_label).innerHTML = pname;	 
		  orgBColor = el.bgColor;
		  orgTColor = el.style.color;
		  el.bgColor=backColor;
		  el.style.color=textColor;
		  preE5 = el;
		  ajax_load_picture_main(pid);

}
function ajax_load_picture_main(pid){
		display("Loading   ",'ajax_loading');
            oXMLHttp = checkXMLHTTP();
            var setRequest = typeof(oXMLHttp.setRequestHeader);
           if ( oXMLHttp && setRequest!="undefined" )
              {
 var myQuery = '&pid='+pid;
 orderPost( oXMLHttp, "?sMod=invoice&CaseAction=load_piture_product&ismain=1", myQuery, HTTPShow_product_picture, true );
 		}		
}

function change_tab(tab_enable,tab_disable){
	var tabEnable 	=	document.getElementById(tab_enable);
	var tabDisable 		=	document.getElementById(tab_disable);
			tabDisable.style.display= 'none';
			tabEnable.style.display= '';
	
	}
function enable_div(div_id){
	var div=	document.getElementById(div_id);
	
	}

function convert_jsa_to_phpa(jsa){
	var new_a = new Array();
	var string_arr='';
	for(var j=0; j<jsa.length; j++ )
			{
				new_a.push(jsa[j].toString());
			}
	for(var j=0; j<new_a.length; j++ ){
		if(j==0) string_arr= new_a[j]; else
			string_arr = string_arr+"139211"+new_a[j];
			}
			return string_arr;
	}


function edit_mode(inven_no,pid,cosref,iscombo){
	var serial_invoice = document.getElementById('serial_invoice').value;	
	if( (serial_invoice.length == 0) || (serial_invoice == '') )
		alert("Not Found serial of this invoice, can not continues process!\nReset System, please.");
	else 
	currentWindow = window.open('?sMod=invoice&CaseAction=add_product_to_invoice_layer&editMode=1&pid='+pid+"&serial_invoice="+serial_invoice+"&costreference="+cosref+"&serial="+inven_no+"&iscombo="+iscombo, "Choose exist invoice","location=0,status=0,scrollbars=0, directories =0, menubar=0,toolbar=0, resizable=0,width=800,height=500");	
	currentWindow.window.moveTo(100,100);
	currentWindow.window.focus();
	//OpenWindow(,'','toolbar=no, menubar=no, scrollbars=no, resizable=no,',1024,728, true);
	}

function check_enter_key(e,obj,frmID){
        var ASCII_Code = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;	
		var char = eval("String.fromCharCode("+ASCII_Code+")") ;
			if (ASCII_Code != 13) 
                { 
				// nothing to do
				}else {
					executeSearchProductList("0",frmID);
                 	 }
                    
			}
function set_value_to_txtbox(source, destination){
	var obj_dest= document.getElementById(destination);	
	return obj_dest.value = source.value;
	}
	


function reFresh_opner_page()
		{
			if(document.getElementById('check_submit_exits').value==0)
			{
				window.opener.location.href = "?sMod=invoice&CaseAction=''";
			}
			else
			window.opener.location.href = "?sMod=invoice";
			window.opener.focus();
			window.close();
		}
		
function focus_invoice_no(){
		 var obj=document.NEW_INVOICE_FRM.focus_invoice_no;
		 obj.focus()
		}
//**************************************************************************//

var preEl ;
var orgBColor;
var orgTColor;		
function HighLightTR(el,serial){
		var backColor='#E7E7E7';
		var textColor='#00CC00';
		var selected=document.getElementById('first_row_id').value;
		var first_row=document.getElementById(selected);
		if(typeof(first_row)!='undefined'){
				first_row.style.color="#333333";
			}
		
		  if(typeof(preEl)!='undefined'){
				preEl.bgColor=orgBColor;
				preEl.style.color=orgTColor;
		 	 }
		  orgBColor = el.bgColor;
		  orgTColor = el.style.color;
		  el.bgColor=backColor;
		  el.style.color=textColor;
		  preEl = el;

var invoice_serial_selected = 	document.getElementById('invoice_serial_selected');
invoice_serial_selected.value = serial;

}

function check_error_add_new_invoice(frm_name){
		var frm = document.getElementById(frm_name);
					if(frm.invoicedate_new.value.length==0)
						{
						display("Please Select invoice date!",'invoicedate_error');
						frm.button2222.focus();
						return false;
						}	
					if(frm.invoicenum.value.length==0)
						{
						display("Please Enter invoice number!", 'invoicenum_error');
						frm.invoicenum.focus();
						return false;
						}
					if(frm.vendorreference_display.value.length==0)
						{
						display("Please Enter vender!",'vendorreference_error');
						frm.vendorreference_display.focus();
						return false;
						}					
		send_vender();	
		
		}
		
		

function check_Number(strNumber)
		{
		var	number ="0123456789.-";
		var vt,kt,l,result;
		var f_dot_pos,l_dot_pos;
		result= true;
		for(i=0;i<8;i++)
				{
				kt= strNumber.charAt(i);
				vt=number.indexOf(kt);
				if(vt==-1){
						 result=false;
						 break;
						}
		
			}// end for
/*	if(result==true){
			   f_dot_pos = strNumber.indexOf('.');
			   l_dot_pos = strNumber.lastIndexOf('.');
			   if(f_dot_pos ==0) ; result= false;
			   if(f_dot_pos!=l_dot_pos) result= false;
			}
			alert(f_dot_pos);
			alert(l_dot_pos);
			alert(result);
	if(result==true){
			 var  f_minus_sign= strNumber.indexOf('-');	   
			   if(f_minus_sign!= -1 || f_minus_sign!=-0) result= false;
			}	*/	
		return result;
	}

var preE2 ;	
function HighLightTR_inventory(el,serial){
		var backColor='#E7E7E7';
		var textColor='#00CC00';
		var selected=document.getElementById('first_row_id').value;
		var first_row=document.getElementById(selected);
		if(typeof(first_row)!='undefined'){
				first_row.style.color="#333333";
			}
		
		  if(typeof(preE2)!='undefined'){
				preE2.bgColor=orgBColor;
				preE2.style.color=orgTColor;
		 	 }
		  orgBColor = el.bgColor;
		  orgTColor = el.style.color;
		  el.bgColor=backColor;
		  el.style.color=textColor;
		  preE2 = el;

}
var preE3 ;	
function HighLightTR_CRV(el){
		var backColor='#E7E7E7';
		var textColor='#00CC00';
		var selected=document.getElementById('first_row_id_crv').value;
		var first_row=document.getElementById(selected);
		if(typeof(first_row)!='undefined'){
				first_row.style.color="#333333";
			}
		
		  if(typeof(preE3)!='undefined'){
				preE3.bgColor=orgBColor;
				preE3.style.color=orgTColor;
		 	 }
		  orgBColor = el.bgColor;
		  orgTColor = el.style.color;
		  el.bgColor=backColor;
		  el.style.color=textColor;
		  preE3 = el;

}
var preE4;	
function HighLightTR_Product(el,pid,pname,id_label){
		var backColor='#E7E7E7';
		var textColor='#00CC00';
		var selected=document.getElementById('id_first_line_product').value;
		var first_row=document.getElementById(selected);
		if(typeof(first_row)!='undefined'){
				first_row.style.color="#333333";
			}
		  if(typeof(preE4)!='undefined'){
				preE4.bgColor=orgBColor;
				preE4.style.color=orgTColor;
		 	 }
		document.getElementById(id_label).innerHTML = pname;	 
		  orgBColor = el.bgColor;
		  orgTColor = el.style.color;
		  el.bgColor=backColor;
		  el.style.color=textColor;
		  preE4 = el;
		  ajax_load_picture(pid);

}
function ajax_load_picture(pid){
		display("Loading   ",'ajax_loading');
            oXMLHttp = checkXMLHTTP();
            var setRequest = typeof(oXMLHttp.setRequestHeader);
           if ( oXMLHttp && setRequest!="undefined" )
              {
 var myQuery = '&pid='+pid;
 orderPost( oXMLHttp, "?sMod=invoice&CaseAction=load_piture_product", myQuery, HTTPShow_product_picture, true );
 		}		
}
function HTTPShow_product_picture()
                        {
                           if ( typeof(oXMLHttp)==='undefined' )
                               return;
							  
                            // Return status of XMLHttp object
                            if ( oXMLHttp.readyState==4 )
                            { 
                                // if oXMLHttp.status is OK
                                if ( oXMLHttp.status==200 )
                                {    
                                    sRes = ((oXMLHttp.responseText));
                                    oJson = sRes.parseJSON(); 
                                     if ( typeof( oJson ) === 'object' )
                                        { if ( oJson['BODY']['RES'] != '' )
											document.getElementById('piture_product_search').innerHTML = oJson['BODY']['RES'];
                                        }	
                                }
								display("",'ajax_loading');
                                if ( oXMLHttp.status==404)
                                {
                                    alert("Page not found");
                                }
                            }
                        
                        }	
function numbersonly(e,obj, length){
		var maxlength=length
		if (obj.value.length>maxlength)
		obj.value=obj.value.substring(0, maxlength);
		
		var unicode=e.charCode? e.charCode : e.keyCode;
			if ((unicode!=8)&&(unicode!=9)&&(unicode!=37)&&(unicode!=38)&&(unicode!=39)&&(unicode!=40)&&(unicode!=46))
					{
					if (unicode<48||unicode>57) //if not a number
					return false; //disable key press
					}
			}
function Trim(sString)
   {
            while (sString.substring(0,1) == " ")
            {
                sString = sString.substring(1, sString.length);
              }
                while (sString.substring(sString.length-1, sString.length) == " ")
                     {
                     sString = sString.substring(0,sString.length-1);
                  }


                                    return sString;
                               }
function round(number,X) {// 
	// rounds number to X decimal places, defaults to 2
	X = (!X ? 2 : X);
	return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
	}
	
	
	
	

function php_serialize(obj)
{
    var string = '';

    if (typeof(obj) == 'object') {
        if (obj instanceof Array) {
            string = 'a:';
            tmpstring = '';
            count = 0;
            for (var key in obj) {
                tmpstring += php_serialize(key);
                tmpstring += php_serialize(obj[key]);
                count++;
            }
            string += count + ':{';
            string += tmpstring;
            string += '}';
        } else if (obj instanceof Object) {
            classname = obj.toString();

            if (classname == '[object Object]') {
                classname = 'StdClass';
            }

            string = 'O:' + classname.length + ':"' + classname + '":';
            tmpstring = '';
            count = 0;
            for (var key in obj) {
                tmpstring += php_serialize(key);
                if (obj[key]) {
                    tmpstring += php_serialize(obj[key]);
                } else {
                    tmpstring += php_serialize('');
                }
                count++;
            }
            string += count + ':{' + tmpstring + '}';
        }
    } else {
        switch (typeof(obj)) {
            case 'number':
                if (obj - Math.floor(obj) != 0) {
                    string += 'd:' + obj + ';';
                } else {
                    string += 'i:' + obj + ';';
                }
                break;
            case 'string':
                string += 's:' + obj.length + ':"' + obj + '";';
                break;
            case 'boolean':
                if (obj) {
                    string += 'b:1;';
                } else {
                    string += 'b:0;';
                }
                break;
        }
    }

    return string;
}





var preEl5 ;
function HighLightTR_Iscombo_Row(el,serial,pid){
		var backColor='#E7E7E7';
		var textColor='#00CC00';
		var selected=document.getElementById('id_first_iscombo_item').value;
		var first_row=document.getElementById("tr_"+selected);
		if(typeof(first_row)!='undefined'){
				first_row.style.color="#333333";
			}
		
		  if(typeof(preEl5)!='undefined'){
				preEl5.bgColor=orgBColor;
				preEl5.style.color=orgTColor;
		 	 }
			 
		  orgBColor = el.bgColor;
		  orgTColor = el.style.color;
		  el.bgColor=backColor;
		  el.style.color=textColor;
		  preEl5 = el;
		  
	ajax_load_picture(pid);
}
function check_error_save_list_product(){
	var buy_txt 				= document.getElementById('buy_txt');
	var case_txt 				= document.getElementById('case_txt') ;	
	var disccount_txt 			= document.getElementById('disccount_txt');	
	var pack_txt			 	= document.getElementById('pack_txt');		

					if(buy_txt.value.length==0)
						{
						display("Not allow empty",'empty_buy_txt');
						buy_txt.focus();
						return false;
						}	
					if(case_txt.value.length==0)
						{
						display("Not allow empty",'empty_case_txt');
						case_txt.focus();
						return false;
						}	
							
					if(disccount_txt.value.length==0)
						{
						display("Not allow empty",'empty_disccount_txt');
						disccount_txt.focus();
						return false;
						}	
							
					if(pack_txt.value.length==0)
						{
						display("Not allow empty",'empty_pack_txt');
						pack_txt.focus();
						return false;
						}	
						
														
	return true;
	}
function enable_this_module(div_id){
	document.getElementById(div_id).style.display='';
	popup.open(div_id);
	
}
function set_undefined_window(){
	window.opener.currentWindow='undefined';
}

function disable_other_button(){
	//document.getElementById('ok_new_crv_btt').
	document.getElementById('cancel_new_adjustment').disabled='disabled';
	document.getElementById('ok_new_adjustment').disabled='disabled';
	document.getElementById('delete_this_adjustment').disabled='disabled';
	}
	
function enableOrDisableDivTag(div_id) {
	toggleDisabled(document.getElementById(div_id));
}
function toggleDisabled(el) {
	try {
		el.disabled = el.disabled ? false : true;
		}
		catch(E){
		}
	if (el.childNodes && el.childNodes.length > 0) {
		for (var x = 0; x < el.childNodes.length; x++) {
		toggleDisabled(el.childNodes[x]);
		}
	}
}
function save_new_product(){
	// The first step - check empty text fill
	//if(!checkEmptyForm("frmNewProduct"))
	 //	return false;
	getAllValueOfRadioAndCheckboxArray("frmNewProduct");
	var frm =	document.getElementById("frmNewProduct");
	// prepare for send data,

	var text = tinyMCE.get('product_description').getContent();
		frm.product_description.value = text;	
	product_description_normal = document.getElementById("product_description_normal").value;
	if(parseInt(product_description_normal)==0)
		frm.product_description.value = frm.product_description_html_tag.value;
// get mobile description version
	 var val = getCheckedValue(frm.product_description_swich);
	if(val == 1){
		var text_2 = tinyMCE.get('product_description_on_mobile').getContent();
		frm.product_description_on_mobile.value = text_2;	
		frm.product_description_on_mobile.value = frm.product_description.value;
	}

	
	frm.submit();
	}

/*
// Created By tienhv
// Date: 14th April 2009
// The follow funtion :
// Browse through all element of function and check radio button ,
// it get value of radio button
// And return to form to submit 
*/
function getAllValueOfRadioAndCheckboxArray(frmID){
	var form = document.getElementById(frmID);
	var formLength = form.elements.length;
		for (i=0; i<formLength; i++)
			{
				var type = form.elements[i].type;

					if (type=="radio"){
						form.elements[i].value =getCheckedValue(form.elements[i]);
					}
					if (type=="checkbox")
						if(form.elements[i].checked)
							{
							form.elements[i].value = "1";
							}
						else 
							{
							form.elements[i].value = "0";
							//alert(form.elements[i].name+" value "+form.elements[i].value);
							}
					
				
			}
		
	}
/*
// Created By tienhv
// Date: 14th April 2009
// The follow funtion :
// it get value  each radio button
*/
function getCheckedValue(radioObj) {
	if(!radioObj)
		return 0;
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return 0;
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return 0;
}
function setCheckedRadio(radioObj,valueCompare){
	var radioLength = radioObj.length;
/*	alert(radioObj.type);
	if(radioLength == undefined) return;
	for(var z = 0; z < radioLength; z++)*/
			if(parseInt(radioObj.value) == parseInt(valueCompare)) {
				radioObj.checked = 'checked' ;
				//break;
		}
	}
function checkEmptyForm(frmID){
	var form = document.getElementById(frmID);
		for (i = 0; i < form.elements.length; i++) {
			if (form.elements[i].type == "text" && form.elements[i].value == "" && (form.elements[i].readonly != 'readonly' || form.elements[i].readonly == false || form.elements[i].disabled == ''  )){
				alert("Please fill out all fields.")
				form.elements[i].focus();
				form.elements[i].style.background ="#FFFFCC";
				form.elements[i].onkeypress  = function(){
														form.elements[i].style.background ="#FFFFFF";	
														};
				return false;
			}
		}
	return true;
	}
function selectedValueOfSelectbox(selectBox_id,valueCompare){
	var selectBoxK = document.getElementById(selectBox_id);
	var selectBoxLength_k = selectBoxK.length;
		if(selectBoxLength_k>0)
		for (var k =0; k<selectBoxLength_k; k++)
				if(selectBoxK.options[k].value == valueCompare)
					{
					selectBoxK.selectedIndex = k;
					break;
					}
		}

function filterProduct(formId){
	if(!checkEmptyForm(formId))
			return false;
	var form = document.getElementById(formId);
	ajax_filterProduct(form.fromDate.value,form.toDate.value);
	}
function ajax_filterProduct(fromDate,toDate){
	popup.open('loading');
            oXMLHttp = checkXMLHTTP();
            var setRequest = typeof(oXMLHttp.setRequestHeader);
           if ( oXMLHttp && setRequest!="undefined" )
              {
 var myQuery = '&fromDate='+fromDate+'&toDate='+toDate;
 orderPost( oXMLHttp, "?sMod=product_index&sAction=filterProduct", myQuery, HTTPShow_ListProduct, true );
 		}		
}
function HTTPShow_ListProduct()
                        {
                           if ( typeof(oXMLHttp)==='undefined' )
                               return;
							  
                            // Return status of XMLHttp object
                            if ( oXMLHttp.readyState==4 )
                            { 
                                // if oXMLHttp.status is OK
                                if ( oXMLHttp.status==200 )
                                {    
									sRes = ((oXMLHttp.responseText));
                                    oJson = sRes.parseJSON(); 
                                     if ( typeof( oJson ) === 'object' )
                                        {
/*-------------------------------------------------------------------------------------------------------------------------------*/											
											if ( oJson['BODY']['RES'] != null )
											{
											var respontext= oJson['BODY']['RES'];	
											display(respontext,'listProduct');
											popup.close('loading');
											}
	/*-------------------------------------------------------------------------------------------------------------------------------*/													
                                        }	
                                }
							//	display("",'ajax_loading');
                                if ( oXMLHttp.status==404)
                                {
                                    alert("Page not found");
                                }
                            }
						}
function check_count_image(pictures_id){
	if(parseInt(count_image)<3){
		popup.open('loading');
		var product_id = document.getElementById('product_id').value;
			oXMLHttp = checkXMLHTTP();
			var setRequest = typeof(oXMLHttp.setRequestHeader);
			if ( oXMLHttp && setRequest!="undefined" ){
				var myQuery = '&pictures_id='+pictures_id+'&product_id='+product_id;
				orderPost( oXMLHttp, "?sMod=upload_image_product&sAction=upDateListImage", myQuery, HTTPShow_ListImageP, true );	
				}
	} else {
		alert("There are three images selected!\nCan not upload more iamges");
		return false;
		}
		}
function HTTPShow_ListImageP()
                        {
                           if ( typeof(oXMLHttp)==='undefined' )
                               return;
                            // Return status of XMLHttp object
                            if ( oXMLHttp.readyState==4 )
                            { 
                                // if oXMLHttp.status is OK
                                if ( oXMLHttp.status==200 )
                                { 
									sRes = ((oXMLHttp.responseText));
                                    oJson = sRes.parseJSON();
                                     if ( typeof( oJson ) === 'object' )
                                        {
/*-------------------------------------------------------------------------------------------------------------------------------*/											
											if ( oJson['BODY']['RES'] != null )
											{
											var respontext= oJson['BODY']['RES'];
											display(respontext,'exist_current_image');
											count_image= parseInt(oJson['BODY']['count_image']);
											popup.close('loading');
											}
	/*-------------------------------------------------------------------------------------------------------------------------------*/													
                                        }	
                                }
							//	display("",'ajax_loading');
                                if ( oXMLHttp.status==404)
                                {
                                    alert("Page not found");
                                }
                            }
						}
function remove_image_item_product(pictures_id,product_id_fieldtext,pictures_file_name){
	var product_id = document.getElementById(product_id_fieldtext).value;
	if(Trim(product_id)=='')
			alert("Not found product id");
		else {// call ajax
			popup.open('loading');
			oXMLHttp = checkXMLHTTP();
			var setRequest = typeof(oXMLHttp.setRequestHeader);
			if ( oXMLHttp && setRequest!="undefined" ){
				var myQuery = '&pictures_id='+pictures_id+'&product_id='+product_id+'&pictures_file_name='+pictures_file_name;
				orderPost( oXMLHttp, "?sMod=upload_image_product&sAction=deleteImageList", myQuery, HTTPShow_ListImageP, true );	
				}
			}

	}
function ajax_upload_image(formID){
	var form = document.getElementById(formID);
	var product_id = document.getElementById("product_id").value;
	if(Trim(product_id)=='')
			alert("Not found product id");
		else {// call ajax
		var pictures_file_name = form.pictures_file_name.value;
		var pictures_comment = form.pictures_comment.value;
		var pictures_title = form.pictures_title.value;
		var pictures_note = form.pictures_note.value;
			popup.open('loading');
			oXMLHttp = checkXMLHTTP();
			var setRequest = typeof(oXMLHttp.setRequestHeader);
			if ( oXMLHttp && setRequest!="undefined" ){
				var myQuery = '&pictures_file_name='+pictures_file_name+'&pictures_comment='+pictures_comment+'&pictures_title='+pictures_title;
				myQuery += '&pictures_note='+pictures_note;
				orderPost( oXMLHttp, "?sMod=upload_image_product&sAction=exe_upload_image", myQuery, HTTPShow_All_image, true );	
				}
			}

	}
function HTTPShow_All_image(){
	  if ( typeof(oXMLHttp)==='undefined' )
                               return;
                            // Return status of XMLHttp object
                            if ( oXMLHttp.readyState==4 )
                            { 
                                // if oXMLHttp.status is OK
                                if ( oXMLHttp.status==200 )
                                { 
									sRes = ((oXMLHttp.responseText));
									alert(sRes);
                                    oJson = sRes.parseJSON();
                                     if ( typeof( oJson ) === 'object' )
                                        {
/*-------------------------------------------------------------------------------------------------------------------------------*/											
											if ( oJson['BODY']['RES'] != null )
											{
											var respontext= oJson['BODY']['RES'];
											display(respontext,'PRODUCT_EXIST_MAIN');
											popup.close('loading');
											}
	/*-------------------------------------------------------------------------------------------------------------------------------*/													
                                        }	
                                }
							//	display("",'ajax_loading');
                                if ( oXMLHttp.status==404)
                                {
                                    alert("Page not found");
                                }
                            }
	
	}
function check_empty_image(formID){
	var form = document.getElementById(formID);	
	if(form.pictures_file_name.value=='')
		{
			display("Empty Field!",'error_empty_file');
			form.pictures_file_name.focus();
			return false;
		}
	form.submit();
	}
function none_error(div_id){
	display("",div_id);
	}
function executeSearchProductList(and_or,frmID){
	var form = document.getElementById(frmID);	
	var pictures_title 		= form .pictures_title_txt.value; 
	var pictures_file_name	= form .pictures_file_txt.value; 
	var pictures_note		= form .pictures_note_txt.value; 		
		//call ajax
		popup.open('loading');
		oXMLHttp = checkXMLHTTP();
		var setRequest = typeof(oXMLHttp.setRequestHeader);
		if ( oXMLHttp && setRequest!="undefined" ){
		var myQuery = '&pictures_file_name='+pictures_file_name+'&pictures_title='+pictures_title;
		myQuery += '&pictures_note='+pictures_note+'&and_or='+and_or;
		orderPost( oXMLHttp, "?sMod=upload_image_product&sAction=filter_image", myQuery, HTTPShow_Filter_Image, true );	
					}
	
	}
function HTTPShow_Filter_Image(){
  if ( typeof(oXMLHttp)==='undefined' )
                               return;
                            // Return status of XMLHttp object
                            if ( oXMLHttp.readyState==4 )
                            { 
                                // if oXMLHttp.status is OK
                                if ( oXMLHttp.status==200 )
                                { 
									sRes = ((oXMLHttp.responseText));
                                    oJson = sRes.parseJSON();
                                     if ( typeof( oJson ) === 'object' )
                                        {
	/*-----------------------------------------------------------------------------------*/											
											if ( oJson['BODY']['RES'] != null )
											{
											var respontext= oJson['BODY']['RES'];
											display(respontext,'PRODUCT_EXIST_MAIN');
											popup.close('loading');
											}
	/*-------------------------------------------------------------------------------------*/													
                                        }	
                                }
							//	display("",'ajax_loading');
                                if ( oXMLHttp.status==404)
                                {
                                    alert("Page not found");
                                }	
	}
}
function check_enter_key_ajaxInfor(e,obj){
        var ASCII_Code = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;	
		var char = eval("String.fromCharCode("+ASCII_Code+")") ;
			if (ASCII_Code != 13) 
                { 
				// nothing to do
				}else {
					var sAction = document.getElementById('sAction').value;
					if(sAction=='do_edit')
						ajax_Load_Infor(obj.value);
						
                 	 }
                    
			}
function ajax_Load_Infor(product_id){
	popup.open('loading');
			oXMLHttp = checkXMLHTTP();
			var setRequest = typeof(oXMLHttp.setRequestHeader);
			if ( oXMLHttp && setRequest!="undefined" )
			{
	product_id = Trim(product_id);	
	if(product_id==''){
		display("Please, enter product_id",'empty_prioduct_id');
		popup.close('loading');
		return false;
		}
	var myQuery = '&product_id='+product_id;
	orderPost( oXMLHttp, "?sMod=product_index&sAction=AJAX_GET_INFOR", myQuery, HTTP_Result_bind_data, true );
			}
	}
function HTTP_Result_bind_data(){	   
		   if ( typeof(oXMLHttp)==='undefined' )
			   return;
			// Return status of XMLHttp object
			if ( oXMLHttp.readyState==4 )
			{
				// if oXMLHttp.status is OK
				if ( oXMLHttp.status==200 )
				{
				   
					sRes = ((oXMLHttp.responseText));
					oJson = sRes.parseJSON(); 
					 if ( typeof( oJson ) === 'object' )
						{	
                  	  if ( oJson['BODY']['RES'] != null )
                   			 {	
					/**********************/
							fill_data_to_form(oJson['BODY'],'frmNewProduct');// fill data to form element
							var image_string_special= oJson['BODY']['image_string_special'];	 // Show image
								display(image_string_special,'ELEMENT_TO_PRINT_IMAGE');
						/* 
						*
						* Other method transport
						*/	
						var other_method_trans= oJson['BODY']['string'];	 // Show OMoT1
						var other_method_body= document.getElementById('other_method_body');
						display(other_method_trans,'other_method_body');
							//other_method_body.appendChild(document.createTextNode(other_method_trans));
//						alert(other_method_body.innerHTML);
						//other_method_body.innerHTML = '';
						
						if(isArray(oJson['innerData'])){
							var l= oJson['innerData'].length;
							for(var y=0; y<l;y++){
							// set inner after we have another data ;
	setInnerHTMLForTdSwich(parseInt(oJson['innerData'][y][0]),oJson['innerData'][y][1],oJson['innerData'][y][2],oJson['innerData'][y][3]);
										}
										
									}
						
								
							/*Set tab html or tab normal*/
							var product_description_normal_v = document.getElementById('product_description_normal').value;
							if(parseInt(oJson['BODY']['product_description_normal']) == parseInt(product_description_normal_v))
									if(product_description_normal_v==1)
										setTabInitialize_Edit('tabber_Enter_normal','tabber_Enter_HTML_tag',0,1);// normal here
									else 
										setTabInitialize_Edit('tabber_Enter_HTML_tag','tabber_Enter_normal',1,0);// html here
	
					/*Tab mobile description */
							if(parseInt(oJson['BODY']['product_description_swich']) == 1 )
								change_tab('mobile_version_des_div_disable','mobile_version_des_div_enable');// also display 
							else 
								change_tab('mobile_version_des_div_enable','mobile_version_des_div_disable');// other show
				/*Tab payment*/
							if(parseInt(oJson['BODY']['product_payment_method']) == 1 )
								enableOrDisableDivTag('bank_name_div'); else enableOrDisableDivTag('bank_name_div');
							enableOrDisableDivTag('set_link_to_price_list_page');
					/**********************/	
							} else
								alert("Not found product id you have typed on system\nPlease retype product id!");
						document.getElementById('sAction').value='do_edit';		
						document.getElementById('pictures_product_id').value = oJson['BODY']['product_id'];	
						popup.close('loading');
						}	
				}
				if ( oXMLHttp.status==404)
				{
					alert("Page not found");
				}
			}
		
		}
function ajax_Load_Infor_Image(product_id){
	popup.open('loading');
			oXMLHttp_Image = checkXMLHTTP();
			var setRequest = typeof(oXMLHttp_Image.setRequestHeader);
			if ( oXMLHttp_Image && setRequest!="undefined" )
			{
	product_id = Trim(product_id);	
	if(product_id=='')	return false;
	var myQuery = '&product_id='+product_id;
	orderPost( oXMLHttp_Image, "?sMod=product_index&sAction=AJAX_RELOAD_IMAGE", myQuery, HTTP_Result_bind_data_image, true );
			}
	}
function HTTP_Result_bind_data_image(){	   
		   if ( typeof(oXMLHttp_Image)==='undefined' )
			   return;
			// Return status of XMLHttp object
			if ( oXMLHttp_Image.readyState==4 )
			{
				// if oXMLHttp_Image.status is OK
				if ( oXMLHttp_Image.status==200 )
				{
				   
					sRes = ((oXMLHttp_Image.responseText));
					oJson = sRes.parseJSON(); 
					 if ( typeof( oJson ) === 'object' )
						  if ( oJson['BODY']['RES'] != null )
								 {		
								 var respontext= oJson['BODY']['RES'];	 
								display(respontext,'ELEMENT_TO_PRINT_IMAGE');
								popup.close('loading');
								}	
				}
			if ( oXMLHttp_Image.status==404)
						alert("Page not found");
			}
		
		}
/*
* Created by: Tienhv
* Date : 19th April 2009;
*/
function fill_data_to_form(array_data,formID){
	var form = document.getElementById(formID);
	var name_e,selectBox_id,valueCompare;
	var type_e ;
		for (i = 0; i < form.elements.length; i++) {
			type_e = form.elements[i].type;
			// fill data to textbox
			if (type_e == "text" || type_e == "hidden"){
					name_e = form.elements[i].name;
				form.elements[i].value = array_data[name_e];
				}
// fill data to select-one
			if (type_e == "select-one" ){
					name_e = form.elements[i].name;	
					selectBox_id = form.elements[i].id;
					valueCompare = array_data[name_e];
					selectedValueOfSelectbox(selectBox_id,valueCompare);				
				}
/*
// fill data to checkbox
*/
			if (type_e == "checkbox" ){
					name_e = form.elements[i].name;	
					if(parseInt(array_data[name_e]) ==1)
						form.elements[i].checked = 'checked';
					else 
						form.elements[i].checked = '';
				}
/*
// fill data to radio
*/	
			if (type_e=="radio"){
					name_e = form.elements[i].name;	
					setCheckedRadio(form.elements[i],array_data[name_e]);
					}
/*
// fill data to radio
*/	
			if (type_e=="textarea"){
					name_e = form.elements[i].name;	
					if(name_e!="product_description_on_mobile_unactive") // exception
						if(name_e == "product_description_html_tag") // exception
							form.elements[i].value= array_data['product_description'];
						else 
						form.elements[i].value= array_data[name_e];
							
					}					
		}	// End for
	}// End function

function back_to_edit_page(){
	var frm = document.getElementById('back_to_edit_page_frm');
	if(frm.id == '' )
		alert("Not found!\nProduct id is missing.");
		else frm.submit();
	}
function check_length(input_textbox,swichText){
	var input_e = document.getElementById(input_textbox);
	var value_to_check =Trim(input_e.value);
	var swich = swichText.substring(0,swichText.length-1);//Syntax: string.substring(start, stop);
	if(value_to_check !=''){
			if(swich == 'other_link_to_price_list_')
				{
		//If you want foucus on IE
		// You must remember a thing
		// Text box which you want to focus need show before call focus();
				popup.open("popup_set_link");	
				bindData(swichText,'cache_data_to_OMT');
				}else
					{
					popup.open("set_uniform_national");
					bindData_2(swichText,'cache_data_to_OMT_2')	
					}
		
		}else{
			input_e.focus();
			input_e.value='';
			}
	}
function bindData_2(source,destination){
	//alert(source);alert(destination);
	var frm = document.getElementById(destination);
	var source_value = document.getElementById(source).value;
		frm.cache_other_uniform_price.focus();
		frm.cache_other_uniform_price.value = source_value;
		frm.swichText.value = source;
		}
function bindData(source,destination){
	var frm = document.getElementById(destination);
	var source_value = document.getElementById(source).value;
//	document.getElementById('cache_other_link_id').focus();
		frm.cache_other_link.focus();
		//If you want foucus on IE
		// You must remember a thing
		// Text box which you want to focus need show before call focus();
		frm.cache_other_link.value = source_value;
		frm.swichText.value = source;
		}
function rebindData(source,divId){
	var frm = document.getElementById(source);
	var url = frm.cache_other_link.value;
	if(!CheckValidUrl(url)){
			frm.cache_other_link.focus();
			document.getElementById('url_invalid').style.display ='block';
		}else{
			var cache_to_getId = frm.swichText.value;
			// cache to get td_id
			var id = cache_to_getId.substring(cache_to_getId.length-1,cache_to_getId.length);
			id= parseInt(id);
			if(id==0)
					id=10;
			td_id = getTdId(id);
			setInnerHTMLForTdSwich(1,td_id,url,id);
			document.getElementById(frm.swichText.value).value = url;
			popup.close(divId);
			}
		}
function rebindData_2(source,divId){
	var frm = document.getElementById(source);
	var value = frm.cache_other_uniform_price.value;
	if(!check_Number(value) || (value=='')){
			frm.cache_other_uniform_price.focus();
			document.getElementById('number_invalid').style.display ='block';
		}else{
			var cache_to_getId = frm.swichText.value;
			// cache to get td_id
			var id = cache_to_getId.substring(cache_to_getId.length-1,cache_to_getId.length);
			id= parseInt(id);
			if(id==0)
					id=10;
			td_id = getTdId(id);
			setInnerHTMLForTdSwich(2,td_id,value,id);
			document.getElementById(frm.swichText.value).value = value;
			
			//rebindInnerHTMLOfTd();
			popup.close(divId);
			}
		}
function setInnerHTMLForTdSwich(swich,tdId,valueShow,id){
	var objTd= document.getElementById(tdId);
	objTd.innerHTML ='';// clear text
	var link_del = addLink('','javascript: removeAndSetInitialize(\''+tdId+'\',\''+id+'\');','javascript: removeAndSetInitialize(\''+tdId+'\',\''+id+'\');',"[Remove] ");
	var link_edit='';
	var links;
	if(swich==1){
			var text1 = addElementHTML('font','','','#333333',textS1 ) ;
			var link_o = addLink('',valueShow,''," [Click here to test link!] ",'_blank');
			link_edit = addLink('','javascript: check_length(\'other_title_textbox_'+id+'\',\'other_link_to_price_list_'+id+'\');','javascript: check_length(\'other_title_textbox_'+id+'\',\'other_link_to_price_list_'+id+'\');',"[Edit] ");
			links = new Array(text1,link_o,slash,link_edit,slash,link_del);
		}else{
			
			
			var text1 = addElementHTML('font','','','#333333',textS2_1 ) ;
			var text_mid = addElementHTML('font','','','#333333',valueShow ) ;
			var text2 = addElementHTML('font','','','#333333',textS2_2 ) ;
			link_edit = addLink('','javascript: check_length(\'other_title_textbox_'+id+'\',\'other_uniform_price_'+id+'\');','javascript: check_length(\'other_title_textbox_'+id+'\',\'other_uniform_price_'+id+'\');',"[Edit] ");
			links = new Array(text1,slash,text_mid,slash,text2,link_edit,slash,link_del);
			}
		for(var j=0; j<links.length;j++)
				if(typeof(links[j]) === "object"){// is element html
					if( isArray(links[j]) )
							   for(var m=0; m<links[j].length; m++)
									if(typeof(links[j][m]) === "object")
										myTD.appendChild(links[j][m]);
										 else
										 objTd.innerHTML	+=links[j][m];
					   else   objTd.appendChild(links[j]);
						   
			//myTD.innerHTML=(array_value[j]);
			 }else
				objTd.appendChild(document.createTextNode(links[j]));
	
	}
function removeAndSetInitialize(tdId,id){
	var objTd= document.getElementById(tdId);
		objTd.innerHTML ='';// clear text
	var count_row = checkRows('other_method_trans_tbl');
	<!--Set for hidden-->
	var other_link_to_price_list_i = document.getElementById("other_link_to_price_list_" +id);
	var other_uniform_price_i = document.getElementById("other_uniform_price_" +id);
		other_link_to_price_list_i.value ='';
		other_uniform_price_i.value ='';
	var link_o = addLink('','javascript: check_length(\'other_title_textbox_'+id+'\',\'other_link_to_price_list_'+id+'\');','javascript: check_length(\'other_title_textbox_'+id+'\',\'other_link_to_price_list_'+id+'\');',"Price Table Page Links");
	var link_2 = addLink('','javascript: check_length(\'other_title_textbox_'+id+'\',\'other_uniform_price_'+id+'\');','javascript: check_length(\'other_title_textbox_'+id+'\',\'other_uniform_price_'+id+'\');',"Set uniform national shipping");
	var links = new Array(link_o,slash,link_2);
	 for(var j=0; j<links.length;j++)
					if(typeof(links[j]) === "object"){// is element html
						if( isArray(links[j]) )
								   for(var m=0; m<links[j].length; m++)
										if(typeof(links[j][m]) === "object")
											myTD.appendChild(links[j][m]);
											 else
											 objTd.innerHTML	+=links[j][m];
						   else   objTd.appendChild(links[j]);
							   
				//myTD.innerHTML=(array_value[j]);
				 }else
					objTd.appendChild(document.createTextNode(links[j]));
			
	}
function getTdId(order){
	return "td2_"+order;
	}
/*
*Created by: tienhv ;
* Date: 26th April;
*/
function add_one_more_other_div(){
	var div_cover = document.getElementById('other_method_transport');
	var current_innerHTML = div_cover.innerHTML;
	var current_length = div_cover.childNodes.length;
	var type_node= '';
	var y=1;
	if (div_cover.childNodes && current_length > 0)
		for (var x = 0; x < current_length; x++) 
//		alert(typeof(div_cover.childNodes[x]))	;
			alert(div_cover.childNodes[x].type)	;
				if(div_cover.childNodes[x].type ="text")
					{
						alert(div_cover.childNodes[x].name);
					}


	}

function AddEndRow(tid,countCell,array_value) {//tbody id, count(cell)+value to add
      // first we create <tr> element  
	var  arr_length = array_value.length;
	var j;
	var myTR=document.createElement('tr');
	var myTD_arr = new Array();
      // now we create first cell (<td> element)
	 if(countCell>0 && arr_length>0 )
	 for(j=0; j< countCell;j++)
	 {
	  var myTD=null;
      	myTD=document.createElement('td');
// check the value of array value is text box or normal text
// Upgraded by : TienHV
// Date : 27th April*
				if(typeof(array_value[j]) === "object"){// is element html
					if( isArray(array_value[j]) )
							   for(var m=0; m<array_value[j].length; m++)
									if(typeof(array_value[j][m]) === "object")
										{
										myTD.appendChild(array_value[j][m]);
										}else
										 myTD.innerHTML	+=array_value[j][m];
					   else   myTD.appendChild(array_value[j]);
						   
			//myTD.innerHTML=(array_value[j]);
			 }else
     			myTD.appendChild(document.createTextNode(array_value[j]));
		
		myTD_arr[j] = myTD;
     	myTR.appendChild(myTD);
	  }
      // after that we add our row (tr) to tbody
      document.getElementById(tid).appendChild(myTR);
	  return new Array(myTR,myTD_arr);
      }


	  
function addOtherMethodTrans(obj_btt){// is Combo
	var count_row = checkRows('other_method_trans_tbl');
	if(count_row==10)
				obj_btt.disabled="disabled"	;
				else obj_btt.disabled="";
	var order = count_row+1;
	var textBoxOther_i = addTextbox("other_title_textbox_" +order,"other_title_"+order,"",40);
	var other_link_to_price_list_i = addHiddenElement("hidden","other_link_to_price_list_" +order,"other_link_to_price_list_"+order,"");
	
	var other_uniform_price_i = addHiddenElement("hidden","other_uniform_price_" +order,"other_uniform_price_"+order,"");
	var link_o = addLink('','javascript: check_length(\'other_title_textbox_'+order+'\',\'other_link_to_price_list_'+order+'\');','javascript: check_length(\'other_title_textbox_'+order+'\',\'other_link_to_price_list_'+order+'\');'," Price Table Page Links");
	var link_2 = addLink('','javascript: check_length(\'other_title_textbox_'+order+'\',\'other_uniform_price_'+order+'\');','javascript: check_length(\'other_title_textbox_'+order+'\',\'other_uniform_price_'+order+'\');',"Set uniform national shipping");
	var links = new Array(link_o,slash,link_2);
	array_value_cell 	= new Array(3) ;
		array_value_cell[0]	=  new Array(3) ;
		array_value_cell[0][0]	= textBoxOther_i;
		array_value_cell[0][1]	= other_link_to_price_list_i;
		array_value_cell[0][2]	= other_uniform_price_i;
		array_value_cell[1]	=new Array(3);
		array_value_cell[1][0]	=link_o;
		array_value_cell[1][1]	=slash;
		array_value_cell[1][2]	=link_2;
		array_value_cell[2] = 'Remove this';
	myTR_And_Last_Td = AddEndRow('other_method_body',3,array_value_cell);// Return the tr had 
																		//insert And last tf of this tr
	format_CSS_for_TrInsert('other_method_trans_tbl','other_method_body',myTR_And_Last_Td);
	}
function remove_this_row(tblId,tbody,tr_id){	
	var count_row = checkRows(tblId);
	obj_btt= document.getElementById('one_more_other_button'); 
	if(typeof(obj_btt) === "object")
		if(count_row==10)
				obj_btt.disabled="disabled"	;
				else obj_btt.disabled="";
	MoveItem(tbody,tr_id);
	}
function MoveItem(tbody,tr_id)
{
      var myTbl=document.getElementById(tbody); 
      //var deltr=myTbl.lastChild;
	  var deltr = document.getElementById(tr_id);
      while (deltr.nodeType==3)
         { myTbl.removeChild(deltr);
 
           deltr=myTbl.lastChild; 
		   }
      myTbl.removeChild(deltr);
}


function format_CSS_for_TrInsert(table_id,tbody_id,myTR_And_Last_Td){
	// check even number
/*	if(checkRows(table_id)%2)// neu so luong ban ghi hien tai la chan 
			myTR_And_Last_Td[0].className ="class_tr_insert_if_even_number";// ban ghi se them co class cua so le
	 	 else myTR_And_Last_Td[0].className ="class_tr_insert_odd_number"; */
		 var current_tr = checkRows(table_id);
		myTR_And_Last_Td[0].className ="td1"; 
		 // Thiet lap id cho tr
  		myTR_And_Last_Td[0].id ='tr_other_'+current_tr;
		//myTR_And_Last_Td[0].style.width = "";
		
		myTR_And_Last_Td[1][2].style.cursor = "pointer";
		myTR_And_Last_Td[1][1].style.color = "#009900";
		myTR_And_Last_Td[1][1].id = 'td2_'+current_tr;
		myTR_And_Last_Td[1][2].title = "Remove this row!";
/*		myTR_And_Last_Td[1][1].id		    = "td_one_"+id;
		myTR_And_Last_Td[1][2].id		    = "td_two_"+id;*/
/*		myTR_And_Last_Td[1][0].style.width = "55%";
		myTR_And_Last_Td[1][1].style.width = "15%";
		myTR_And_Last_Td[1][2].style.width = "17%";*/
	   
	  // set su kien onclick cho tr va td	  
/*	  	myTR_And_Last_Td[1][3].onclick  = function(){
		 	remove_this_product_out_list(tbody_id,id);
		}*/
		myTR_And_Last_Td[1][2].onclick  = function(){
			remove_this_row('other_method_trans_tbl','other_method_body',myTR_And_Last_Td[0].id)
		}
/*	 myTR_And_Last_Td[0].onclick  = function(){
		ajax_load_picture(id);
		}*/// function cho tr
	}

function round(number,X) {// 
	// rounds number to X decimal places, defaults to 2
	X = (!X ? 2 : X);
	return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
	}
function checkRows(table_id)  {
   var tbl=document.getElementById(table_id);
   return (tbl.rows.length);
//   for (var i=0; i<tbl.rows.length; i++) 
	}
function addTextbox(ID,name,value,size) {
	//All atrribute must be lowercase before set attribute
	// Because IE detect attribute by chu thuong
	var textbox = document.createElement("input");
	textbox.setAttribute("type",'text');
	textbox.setAttribute("id",ID);
	textbox.setAttribute("name", name);
	//tb.setAttribute("value", tb.getAttribute("ID"));
	textbox.setAttribute("value", value);
	textbox.setAttribute("size", size);
	return textbox;
	//document.getElementById("container").appendChild(tb);
	}
function addElementForm(type,ID,name,value) {
	//var textbox = document.createElement("input");
	textbox.setAttribute("type",type);
	textbox.setAttribute("id",ID);
	textbox.setAttribute("name", name);
	//tb.setAttribute("value", tb.getAttribute("ID"));
	textbox.setAttribute("value", value);
//	textbox.setAttribute("size", size);
	return textbox;
	//document.getElementById("container").appendChild(tb);
	}
function addHiddenElement(type,ID,name,value) {
	var hiddenE = document.createElement("input");
	hiddenE.setAttribute("type",'hidden');
	hiddenE.setAttribute("id",ID);
	hiddenE.setAttribute("name", name);
	//tb.setAttribute("value", tb.getAttribute("ID"));
	hiddenE.setAttribute("value", value);
//	textbox.setAttribute("size", size);
	return hiddenE;
	//document.getElementById("container").appendChild(tb);
	}
function addElementHTML(tag,ID,name,color,value) {
	var ele = document.createElement(tag);
	ele.setAttribute("id",ID);
	ele.setAttribute("name", name);
	ele.setAttribute("color", color);
	ele.appendChild(document.createTextNode(value));
//	ele.setAttribute("value", value);
	return ele;
	}
function addLink(name,href,onclick,text,target) {
	var links = document.createElement('a');
	links.setAttribute('name', name);
	links.setAttribute('href', href);
	links.setAttribute('onclick',onclick );
	if(typeof(target) === 'undefined'){
		links.setAttribute('target','_self');	
	}else
		links.setAttribute('target',target);
	links.appendChild(document.createTextNode(text));
	return links;
	//document.getElementById("container").appendChild(tb);
	}
	
function isArray(obj) {
	  if (obj == null) return false;
	  return obj.constructor == Array;
  }
function CheckValidUrl(strUrl)
      {

      var RegexUrl = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
      return RegexUrl.test(strUrl);

      }

      // Sample use

function update_size_load_html_form(pid_textbox){
            oXMLHttp = checkXMLHTTP();
            var setRequest = typeof(oXMLHttp.setRequestHeader);
           if ( oXMLHttp && setRequest!="undefined" )
              {
				var pid = document.getElementById(pid_textbox).value;
			if(Trim(pid)=='') {	alert("ID not found"); return false;	}
			var myQuery = '&product_id='+pid;
			orderPost( oXMLHttp, "?sMod=product_index&sAction=update_size", myQuery, HTTPShowPopup_update_psize, true );
 			}		
}
function HTTPShowPopup_update_psize()
                        {
                           if ( typeof(oXMLHttp)==='undefined' )
                               return;
							  
                            // Return status of XMLHttp object
                            if ( oXMLHttp.readyState==4 )
                            { 
                                // if oXMLHttp.status is OK
                                if ( oXMLHttp.status==200 )
                                {    
                                    sRes = ((oXMLHttp.responseText));
									alert(sRes);
                                    oJson = sRes.parseJSON(); 
                                     if ( typeof( oJson ) === 'object' )
                                        { if ( oJson['BODY']['RES'] != '' )
											document.getElementById('popup_update_psize_content').innerHTML = oJson['BODY']['RES']
											popup.open('popup_update_psize');
                                        }
                                }
                                if ( oXMLHttp.status==404)
                                {
                                    alert("Page not found");
                                }
                            }
                        
                        }	
function setRadioValue(radioObj){
	if(radioObj.checked)
			{
			radioObj.checked='';
			}else
				{
					radioObj.checked='checked';
				}
	}
function checkUrl(anchors,url){
	var e = document.getElementById(url);
	var vl = e.value;
	if(!CheckValidUrl(vl)){
		 document.getElementById('url_invalid_2').style.display ="block";
		e.focus();
	}
	else{
		anchors.setAttribute('href','http://google.com.vn/?key='+vl);
		alert("4324");
		return true;
		}
	}